package net.oschina.app.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import net.oschina.app.R;
import net.oschina.app.adapter.BaseRecyclerViewAdapter;
import net.oschina.app.bean.Blog;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/4/5.
 * ?
 */

public class BlogAdapter extends BaseRecyclerViewAdapter{
    List<Blog> bloglist;
    public BlogAdapter(Context context, List<Blog> bloglist) {
        super(context);
        this.bloglist = bloglist;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.my_blog_item,null);
        BlogHolder holder = new BlogHolder(view);
        return holder;
    }

    @Override
    public int getItemCount() {
        return bloglist.size();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        //数据
        BlogHolder blogHolder = (BlogHolder) holder;
        Blog blog = bloglist.get(position);
        blogHolder.mReview.setText(blog.getCommentCount()+"");
        blogHolder.mTime.setText(blog.getPubDate());
        blogHolder.mTittleName.setText(blog.getTitle());
        blogHolder.mUserName.setText(blog.getAuthor());





    }

    class BlogHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.titlename)
        TextView mTittleName;
        @BindView(R.id.blog_user_name)
        TextView mUserName;
        @BindView(R.id.blog_review)
        TextView mReview;
        @BindView(R.id.bolg_time)
        TextView mTime;

        public BlogHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
